#!/usr/bin/env bash
while true
do
  sleep 300
  echo "start report series..."
  db_names=$(influx -execute 'SHOW DATABASES' | tail -n +4)
  for db_name in $db_names; do
    meaurement_names=$(influx -database $db_name -execute 'SHOW MEASUREMENTS' | tail -n +4)
    for meaurement_name in $meaurement_names; do
      number_of_series=$(influx -database $db_name -execute "SHOW SERIES FROM \"$meaurement_name\"" | tail -n +3 | wc -l)
      influx -database '_internal' -execute "INSERT table_series,table_name=$meaurement_name,db=$db_name num=$number_of_series"
    done
  done
  echo "end report series..."
done